package essential;

import java.awt.Color;
import java.util.Random;

public class Material {
	
	public Color color;
	public double rIndex;
	
	public double refl;
	public double refr;
	
	public double diff;
	public double spec;
	
	public double intensity;
	public boolean light;

	int currentColor = 0;
	static Random r;

	
	static Color sortedColors[] = {
		new Color(1.0f, 0.0f, 1.0f),	//Violet
		new Color(0.0f, 0.0f, 1.0f),	//Blue
		new Color(0.0f, 1.0f, 0.0f),	//Green
		new Color(1.0f, 1.0f, 0.0f),	//Yellow
		new Color(1.0f, 0.269f, 0.0f),	//Orange, I swear it's orange :3
		new Color(1.0f, 0.0f, 0.0f)};	//Red
	
	// Constructor custom con parametros harcodeados
	public Material(){
		
		if( r == null)
			r = new Random(System.currentTimeMillis());
		
		
		// Initial color
		color = null;
		
		// Reflection and refraction factors

		refl = (1.0f);
		refr = (0.0f);
		
		// Diffuse and specular
		diff =  refr;
		spec = (1.0f - diff);

		// Refraction index
		rIndex = 1.31766;
		
		//Light intensity if primitive is light
		intensity = 1;

	}
	
	static public  Material matteMaterial(){
		
		Material m = new Material();
		
		m.color = null;
		m.refl = m.refr = m.diff = m.spec = 0;
		
		
		return m;
		
	}
	
	
	
	//Constructor default
	public Material(Color c,  
			double reflectionFactor,
			double refractionFactor, 
			double diffuseFactor, 
			double refractionIndex,
			double inten){
		
		// Initial color
		color = c;
		
		// Reflection and refraction factors
		setReflection(reflectionFactor);
		setRefraction(refractionFactor);
		
		// Diffuse and specular
		diff = diffuseFactor;
		spec = (1.0f - diff);
		
		// Refraction index
		setRefractionIndex(refractionIndex);
		
		//Light intensity if primitive is light
		intensity = inten;
	}

	

	public void setIntensity(double intensity) {
		this.intensity = intensity;
	}



	public double getIntensity() {
		return intensity;
	}

	public Color getColor() {
		
		if( color == null)
			color = this.nextColor();
		
		return color;
	}
	
	public Color nextColor() {
		 
		return new Color(r.nextFloat(), r.nextFloat(), r.nextFloat());
	
	}


	public void setColor(Color color) {
		this.color = color;
	}

	public void setLight(Boolean light) {
		this.light = light;
	}
	
	public Boolean isLight() {
		return light;
	}
	
	


	public void setRefractionIndex(double rIndex) {
		this.rIndex = rIndex;
	}



	public double getRefractionIndex() {
		return rIndex;
	}



	public void setReflection(double refl) {
		this.refl = refl;
	}



	public double getReflection() {
		return refl;
	}



	public void setRefraction(double refr) {
		this.refr = refr;
	}



	public double getRefraction() {
		return refr;
	}

	public double getSpecular() {
		return spec;
	}


	public double getDiffuse() {
		return diff;
	}


	public void setDiffuse(double d) {
		diff = d;
		spec = 1 - diff;
	}


	
}
